<?php
namespace app\home\controller;
use app\home\model\AdModel;
use app\home\model\ProductMessageModel;
use app\home\model\ProductModel;
use taobao\AliSms;
use think\Cookie;
use think\Db;

class Trade extends Base
{

    /**
     * listing [ 交易平台列表页 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @return mixed
     */
    public function listing(){

        // +----------------------------------------------------------------------
        // |  取出重点 is_tui = 3
        // +----------------------------------------------------------------------
        $ProductModel = New ProductModel();
        $IsTUIEQThree = $ProductModel->getOneIsTuiEQThree();
        $this->assign('IsTUIEQThree',$IsTUIEQThree);
        // +----------------------------------------------------------------------
        // |  取出四条最新的产品需求
        // +----------------------------------------------------------------------
        $NewProductFour = $ProductModel ->getNewProductFour();
        $this->assign('NewProductFour',$NewProductFour);
        // +----------------------------------------------------------------------
        // |  取出六条最新的产品需求
        // +----------------------------------------------------------------------
        $Success = $ProductModel ->getSuccessSixProduct();
        $this->assign('Success',$Success);
        // +----------------------------------------------------------------------
        // |  取出四条商务合作广告位
        // +----------------------------------------------------------------------
        $AdModel = New AdModel();
        $Ad = $AdModel -> ShangWu();
        $this->assign('Ad',$Ad);

        return $this->fetch();
    }

    /**
     * index [ 交易平台详情页 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @return mixed
     */
    public function index()
    {
        $id = input('param.id');
        $ProductModel = New ProductModel();
        $Product =  $ProductModel -> fetchOneProduct($id);
        $this->assign('Product',$Product);

        // +----------------------------------------------------------------------
        // |  取出随机新闻10条
        // +----------------------------------------------------------------------
        $SuiJiTenNews = $ProductModel->fetchSuiJiNews();
        $this->assign('SuiJiTenNews',$SuiJiTenNews);
        return $this->fetch();
    }

    /**
     * lists [ 更多的企业加盟列表页 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function lists()
    {
        // +----------------------------------------------------------------------
        // |  取出最新的15个需求
        // +----------------------------------------------------------------------
        $ProductModel = New ProductModel();
        $list = $ProductModel->getTenFiveProduct();
        $this->assign('list',$list);
        // +----------------------------------------------------------------------
        // |  取出所有的分类
        // +----------------------------------------------------------------------
        $cate = $ProductModel->getAllProductCate();
        $this->assign('cate',$cate);
        $AllCate = $ProductModel->getAllProductCate();
        $this->assign('AllCate',$AllCate);

        $AllProduct = $ProductModel -> getAllproduct();
        $this->assign('AllProduct',$AllProduct);
       // dump($cate);die;
        return $this->fetch();
    }


    /**
     * message [ 首页需求功能模块 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @return mixed
     */
    public function message()
    {
        if (request()->isAjax()){
            $param = input('param.');

            if ($param['alicode'] !==  cookie::get('code')){
                $res['code'] = 0;
                $res['msg'] ="短信验证失败";
                return json($res);
            }else {
                $ProductMessageModel = New ProductMessageModel();
                return $ProductMessageModel->insertOneMessage($param);
            }
        }else{
            return $this->fetch();
        }
    }


    /**
     * alisms [ 阿里大于发短信验证是否正确 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function alisms()
    {
        if (request()->isAjax()){
            $mobile = input('param.phone');

            if ($this->Ali($mobile)){
                return ['code' => 1,'msg' => '短信发送成功'];
            }else{
                return ['code' => 0,'msg' => '短信发送失败'];
            }

        }else{
            return $this->fetch();
        }
    }


    /**
     * AliSms [ 阿里大于发短信 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @param $mobile
     */
    public function Ali($mobile)
    {
        $code = rand (111111,999999);
        Cookie::set('code',$code,3600);
        $AliSmsModel = New AliSms();
        return  $AliSmsModel ->send_verify($mobile, $code);
    }





}
